/*
**  Apache License, Version 2.0
**  Notes:Use this command to anonymously check out the latest project source code:
**  Non-members may check out a read-only working copy anonymously over HTTP.
**  SVN checkout http://YHHCatiaBaseUtlWsp.googlecode.com/svn/trunk/ 
**
**  Author:		Kevin Yang
**  Email:		Bigearrabbit@qq.com
**
**  DATE:		2013-4-16
**
**  File Name:	YHHVisualizationTools.cpp
**
**  Notes:
** 
*/

//Local Framework
#include "YHHVisualizationTools.h"
#include "YHHCatiaBaseDefine.h"

//InteractiveInterfaces Framework
#include "CATIBuildPath.h"

namespace YHH
{
	//---------------------------------------------------------
	void HSOAppend(CATISpecObject_var ispInput, CATFrmEditor * ipEditor, CATHSO * ipHSO)
	{
		// check input
		if ( NULL_var == ispInput )return; //input error

		if ( NULL == ipEditor )//check ipEditor
		{
			ipEditor = CATFrmEditor::GetCurrentEditor();//get Editor
			if ( NULL == ipEditor )return; //input error
		}

		if ( NULL == ipHSO )//check ipHSO
		{
			ipHSO = ipEditor->GetHSO();//get HSO
			if ( NULL == ipHSO )return; //input error
		}


		// uses this pointer to build a path element
		CATIBuildPath *piBuildPath = NULL;
		HRESULT rc = ispInput->QueryInterface( IID_CATIBuildPath, (void**) &piBuildPath );
		if ( FAILED(rc) )return; //have error

		CATPathElement Context = ipEditor->GetUIActiveObject();
		CATPathElement *pPathElement = NULL ;
		rc = piBuildPath->ExtractPathElement(&Context,&pPathElement);

		if (pPathElement != NULL)
		{   // the geometrical element corresponding to the active field is now highlighted
			ipHSO->AddElement(pPathElement); 

			YHHRelease(pPathElement);//release
		}
		YHHRelease(piBuildPath);//release

	}
	//---------------------------------------------------------
	void HSOAppend(	CATListValCATISpecObject_var ispListInput, CATFrmEditor * ipEditor, CATHSO * ipHSO)
	{
		// check input
		if ( 0 == ispListInput.Size() )return; //input error

		if ( NULL == ipEditor )//check ipEditor
		{
			ipEditor = CATFrmEditor::GetCurrentEditor();//get Editor
			if ( NULL == ipEditor )return; //input error
		}

		if ( NULL == ipHSO )//check ipHSO
		{
			ipHSO = ipEditor->GetHSO();//get HSO
			if ( NULL == ipHSO )return; //input error
		}

		CATPathElement Context = ipEditor->GetUIActiveObject();

		for (int i=1;i<=ispListInput.Size();i++)
		{
			CATISpecObject_var ispInput = ispListInput[i];//get object
			// uses this pointer to build a path element
			CATIBuildPath *piBuildPath = NULL;
			HRESULT rc = ispInput->QueryInterface( IID_CATIBuildPath, (void**) &piBuildPath );
			if ( FAILED(rc) )return; //have error

			CATPathElement *pPathElement = NULL ;
			rc = piBuildPath->ExtractPathElement(&Context,&pPathElement);

			if (pPathElement != NULL)
			{   // the geometrical element corresponding to the active field is now highlighted
				ipHSO->AddElement(pPathElement); 

				YHHRelease(pPathElement);//release
			}
			YHHRelease(piBuildPath);//release
		}


	}
	//---------------------------------------------------------
}//YHH
 
